#!/usr/bin/env python
# -*- coding: utf-8 -*-

import socket

class Config():
    def __init__(self, filename):
        self.VERSION = '0.3b'
        self.HOST = socket.gethostname()
        self.USER = 'admin'
        self.PASS = 'admin'
        self.DB_USER = ''
        self.DB_PASS = ''
        self.WWW_DIR = '/www'
        self.SVN_DIR = '/var/svn'
        self.BACKUP_DIR = '/var/backup'
        self.PORT = 8080
        self.REALM = 'Server Panel Daemon'
        self.MYSQL_DUMP_BIN = '/usr/bin/mysqldump'
        self.BZIP2_BIN = '/bin/bzip2'
        self.TAR_BIN = '/bin/tar'
        self.CRON_EXEC_HOUR = 1
        self.AUTOUPDATE = False
        self.LOGDATETIMEFORMAT = '%d/%m/%Y %H:%M:%S'
        self.ADMINEMAIL = 'javier.perez@secuoyas.com, javier.perez.m@gmail.com'
        
        # cargamos los datos del fichero de configuración
        try:
            f = open(filename, 'r')
            for line in f:
                
                line = line.strip(' \n')
                
                if len(line) > 0 and not line.startswith('#'):
                    
                    tokens = line.split('=', 1)
                    
                    if len(tokens) > 1:
                        token = tokens[0].strip()
                        value = tokens[1].strip()
                        
                        if token == 'db.user':
                            self.DB_USER = value
                        elif token == 'db.pass':
                            self.DB_PASS = value
                        elif token == 'www.dir':
                            self.WWW_DIR = value
                        elif token == 'svn.dir':
                            self.SVN_DIR = value
                        elif token == 'backup.dir':
                            self.BACKUP_DIR = value
                        elif token == 'host':
                            self.HOST = value
                        elif token == 'user':
                            self.USER = value
                        elif token == 'pass':
                            self.PASS = value
                        elif token == 'realm':
                            self.REALM = value
                        elif token == 'port':
                            self.PORT = int(value)
                        elif token == 'bin.mysqldump':
                            self.MYSQL_DUMP_BIN = value
                        elif token == 'bin.bzip2':
                            self.BZIP2_BIN = value
                        elif token == 'cron.exec.hour':
                            self.CRON_EXEC_HOUR = int(value)
    
        except IOError:
            print 'WARNING: cannot open config file: %s' % filename
            
        
